package tesis.utils;

import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

/**
 *
 * @author otto.theo
 */
public final class JSONUtil {

    public static final String EMPTY_JSON_STRING = "[]";

    private JSONUtil() {
    }

    public static String convertListToJSON(List<? extends Serializable> lista) throws JsonGenerationException, JsonMappingException, IOException {
        return convertObjectToJSON(lista);
    }

    public static String convertObjectToJSON(Object obj) throws JsonGenerationException, JsonMappingException, IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        Writer strWriter = new StringWriter();
        objectMapper.writeValue(strWriter, obj);
        return strWriter.toString();
    }
}
